$(function(){
	var currentUrl = window.location.href;
	/*alert(currentUrl);*/
	var willSell=null;//预售字段
	var id = location.search.match(new RegExp("[\?\&]id=([^\&]+)", "i"))[1];
	var p ={id:id};
	 $.ajax({
		  type:"POST",
		  url:"/movie.front/movieInfo/getMovieInfoById",
		  data:JSON.stringify(p),
		  dataType:"json",
		  contentType:"application/json",
		  success:function(data){
            var data = data.result;
           /* var movieTime =   data.movieTime;*/
            willSell = data.isSell;
            if(willSell=="否"){
            	$('#purchase-ticket').hide();
            }
           var html ='<h3>'+data.movieName+'</h3>'+'<ul class="size"><h4>'+data.movieCategory+'</h4></ul>'+
                     '<ul class="size"> <h4>上映时间&nbsp&nbsp'+transfer(data.movieTime)+'</h4></ul><div class="galry"><div class="prices"><h5>价格：'+data.moviePrice+'元</h5>'+
                     '</div><div class="clearfix"></div></div>';
                   $('#check-movieInfo').append(html);
                     var url='http://localhost:8080/';
                      var str ='<li style="list-style:none"><div class="thumb-image"><img class="img-responsive" style="width:280px" src='+url+data.moviePicture+'></div></li><li  id="check-hallId"  style="display:none">'+data.hallId+'</li>';
                      $('.flexslider  ul').append(str);
                      $('#intro-movieInfo').append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font>"+data.movieIntro+"</font>");       
		              $('#hall-title').append('<h4 class="modal-title" id="myModalLable">'+data.hallName+'</h4>');
		     
		              $('#movie-video').append('<video  controls="controls" src='+url+data.videoPath+'>');
		  }
	   });
	
		  $.ajax({
		  type:"POST",
		  url:"/movie.front/peopleController/getPeopelInfo",
		  data:JSON.stringify(p),
		  dataType:"json",
		  contentType:"application/json",
		  success:function(data){
            var arr = data.result;
            var url = 'http://localhost:8080/';
            for(var i=0;i<arr.length;i++){
          var html='<div class="product-grid col-md-1" style="width:200px"><div class="more-product">'+
          '<span></span></div><div class="product-img b-link-stripe b-animate-go thickbox"><img class="img-responsive" alt="" src='+url+arr[i].moviePersonPicture+'>'+
          '<div class="b-wrapper"></div></div><div class="product-info simpleCart_shelfItem"><div class="product-info-cust prt_name"><h4>'+arr[i].personName+'</h4></div></div></div>';
          
             
               $('#picture-personInfo').append(html);
            	}
		    }
	   });
		 
		  /**
		   * 页面跳转
		   */
		  
		  $('#purchase-ticket').click(function(){
			  $.ajax({
				  type:"POST",
				  url:"/movie.front/orderController/getUserInfo",
				  data:JSON.stringify(p),
				  dataType:"json",
				  contentType:"application/json",
				  success:function(data){
		           if(data.result.statusCode!=null){
		        	   alert("您还没有登录，请立即登陆在进行购买");
		        	   window.location.href="account.html";
		           }else{
		        	   window.location.href="checkout.html?id="+id; 
		           }
		           
				    }
			   });
			  
			  // 
		  });
		  
		  $('#myCart').click(function(){
				$.ajax({
					  type:'POST',
					  url:'/movie.front/orderController/getOrderListsByUserId',
					  dataType:'json',
					  contentType:'application/json',
					  success:function(data){
						 if(data.result[0].statusCode!=null){
							  alert(data.result[0].statusCode);
							 window.location.href="account.html";
						 }else{
							 $('#myorders-table').empty();
							 var data =data.result;
							 for(var i=0;i<data.length;i++){
								 var html='';
								 html = html+'<tr><td  align="center">'+data[i].orderName+'</td><td  align="center">'+data[i].orderPrice+'元</td><td  align="center">'+data[i].orderTime+'</td></tr>';
								 $('#myorders-table').append(html);
							 }
						 }
					  }
				});
			});
});		 



function transfer(val){
	if(val){
		val = parseInt(val, 10) * 1000;
		var date = new Date(val);
		//return date.format('yyyy-MM-dd hh:mm:ss');
		return date.format('yyyy-MM-dd hh:mm:00');
	}
	return '';
}
//重写javaScript日期对象原型
Date.prototype.format = function(fmt){
	var o = {
		'M+': this.getMonth() + 1,//月份
		'd+': this.getDate(),//日
		'h+': this.getHours(),//小时
		'm+': this.getMinutes(),//分
		's+': this.getSeconds(),//秒
		'q+': Math.floor((this.getMonth() + 3) / 3),//季度
		'S': this.getMilliseconds()//毫秒
	};
	if(/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
	for( var k in o)
		if(new RegExp('(' + k + ')').test(fmt))
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
	return fmt;
}
